package com.zhuiyun.pm.client.bidding.mapper;

import com.zhuiyun.pm.client.bidding.entity.ClientMyAttention;
import com.zhuiyun.pm.client.bidding.entity.ClientRunningWater;
import com.zhuiyun.pm.config.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClientMyAttentionMapper extends BaseMapper<ClientMyAttention> {
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "goodsId",column = "goods_id"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "updateTime",column = "update_time"),
            @Result(property = "serviceConsultant",column = "service_consultant"),
            @Result(property = "transactionStatus",column = "transaction_status"),
            @Result(property = "goodsName",column = "goods_name"),
            @Result(property = "startTime",column = "start_time"),
            @Result(property = "endTime",column = "end_time"),
            @Result(property = "startPrice",column = "start_price"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "delFlag",column = "del_flag")
    })
    @Select("select i.* from client_my_attention as a\n" +
            "JOIN client_goods_info i\n" +
            "on a.goods_id = i.id\n" +
            "where a.user_id = #{userId}= u.id \n" +
            "and a.del_flag != 1")
    List<ClientMyAttention> findAllByUserId(@Param("userId") Integer userId);

   @Update("update client_my_attention set del_flag = 1 where id = #{id}")
    Integer del(@Param("id") Integer id);

    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "serviceConsultant",column = "service_consultant"),
            @Result(property = "transactionStatus",column = "transaction_status"),
            @Result(property = "goodsName",column = "goods_name"),
            @Result(property = "startTime",column = "start_time"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "endTime",column = "end_time"),
            @Result(property = "startPrice",column = "start_price"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "delFlag",column = "del_flag")
    })
    @Select("select i.* from client_intermediate_table as a\n" +
            "JOIN client_goods_info i\n" +
            "on a.good_id = i.id\n" +
            "where\n" +
            "i.del_flag != 1\n" +
            "and a.user_id = #{userId}")
    List<ClientMyAttention> byid(@Param("userId") Integer userId,@Param("id") Integer id);



    @Select("select a.service_consultant,i.transaction_status,i.goods_name,i.start_time,i.end_time,i.start_price from client_my_attention as a\n" +
            "JOIN client_goods_info i\n" +
            "on a.goods_id = i.id\n" +
            "JOIN client_user u\n" +
            "on  a.user_id= #{userId}= u.id\n" +
            "where\n" +
            "a.del_flag != 1\n" +
            "LIMIT #{page},#{size} ")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "goodsId",column = "goods_id"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "updateTime",column = "update_time"),
            @Result(property = "serviceConsultant",column = "service_consultant"),
            @Result(property = "transactionStatus",column = "transaction_status"),
            @Result(property = "goodsName",column = "goods_name"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "startTime",column = "start_time"),
            @Result(property = "endTime",column = "end_time"),
            @Result(property = "startPrice",column = "start_price"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "delFlag",column = "del_flag")
    })
    List<ClientMyAttention> listpage(@Param("page") Integer page , @Param("size")Integer size,@Param("userId") Integer userId);


}
